package com.janbar.shutdown.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.provider.Settings;
import android.widget.Toast;

import com.janbar.shutdown.MainActivity;


public class StartReceiver extends BroadcastReceiver {

    static final String ACTION = "android.intent.action.BOOT_COMPLETED";

    @Override
    public void onReceive(Context context, Intent intentOld) {

        //检查是否已经授予权限
        if (!Settings.canDrawOverlays(context)) {
            //若未授权则请求权限
            System.out.println("StartReceiveraaa");
            Intent intent = new Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION);
            intent.setData(Uri.parse("package:" + getPackageName()));
            intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            System.out.println("StartReceiverbbb");
            context.startActivity(intent);
            System.out.println("StartReceiverccc");
        }
    }

    private String getPackageName(){
        return "com.janbar.shutdown";
    }
}
